export const learningProcessData = []

// 生成更多随机数据
const generateRandomStudent = (className, index) => {
  const names = ['张', '王', '李', '赵', '陈', '刘', '杨', '黄', '周', '吴', '郑', '孙', '马', '朱', '胡', '林', '郭', '何', '高', '罗', '梁', '宋', '唐', '许', '邓', '冯', '韩', '曹', '曾', '彭', '萧', '蔡', '潘', '田', '董', '袁', '于', '余', '叶', '蒋', '杜', '苏', '魏', '程', '吕', '丁', '沈', '任', '姚', '卢']
  const secondNames = [
    // 单名
    '伟', '芳', '娜', '敏', '静', '丽', '强', '磊', '军', '洋', '勇', '艳', '杰', '娟', '涛', '明', '超', '辉', '玲', '华', '红', '燕', '飞', '龙', '云', '晶', '鑫', '欣', '婷', '雪',
    // 双名 - 传统组合
    '秀英', '秀兰', '秀珍', '秀华', '秀芳', '秀梅', '秀琴', '秀霞', '秀云', '秀芬',
    '志强', '志明', '志华', '志勇', '志刚', '志伟', '志军', '志国', '志强', '志强',
    '文静', '文华', '文娟', '文英', '文芳', '文霞', '文丽', '文秀', '文英', '文华',
    '春华', '春芳', '春梅', '春燕', '春霞', '春兰', '春英', '春丽', '春秀', '春华',
    '玉华', '玉芳', '玉梅', '玉霞', '玉兰', '玉英', '玉丽', '玉秀', '玉华', '玉芳',
    // 双名 - 现代组合
    '子涵', '子轩', '子墨', '子琪', '子萱', '子晴', '子怡', '子欣', '子悦', '子琪',
    '雨晴', '雨欣', '雨彤', '雨菲', '雨涵', '雨轩', '雨泽', '雨辰', '雨桐', '雨琪',
    '梦琪', '梦瑶', '梦婷', '梦洁', '梦华', '梦雪', '梦露', '梦菲', '梦涵', '梦琪',
    '思琪', '思涵', '思雨', '思彤', '思怡', '思颖', '思远', '思源', '思琪', '思涵',
    '佳琪', '佳怡', '佳欣', '佳颖', '佳悦', '佳琪', '佳涵', '佳彤', '佳琪', '佳怡',
    // 双名 - 寓意组合
    '浩然', '浩宇', '浩轩', '浩辰', '浩宇', '浩天', '浩宇', '浩宇', '浩宇', '浩宇',
    '晨曦', '晨光', '晨阳', '晨星', '晨露', '晨风', '晨光', '晨阳', '晨星', '晨露',
    '诗雨', '诗涵', '诗琪', '诗彤', '诗怡', '诗颖', '诗远', '诗源', '诗琪', '诗涵',
    '雅琪', '雅涵', '雅雨', '雅彤', '雅怡', '雅颖', '雅远', '雅源', '雅琪', '雅涵',
    '欣怡', '欣悦', '欣妍', '欣彤', '欣颖', '欣远', '欣源', '欣琪', '欣涵', '欣怡',
    // 双名 - 独特组合
    '梓涵', '梓轩', '梓墨', '梓琪', '梓萱', '梓晴', '梓怡', '梓欣', '梓悦', '梓琪',
    '若曦', '若涵', '若雨', '若彤', '若怡', '若颖', '若远', '若源', '若琪', '若涵',
    '语嫣', '语涵', '语雨', '语彤', '语怡', '语颖', '语远', '语源', '语琪', '语涵',
    '瑾瑜', '瑾涵', '瑾雨', '瑾彤', '瑾怡', '瑾颖', '瑾远', '瑾源', '瑾琪', '瑾涵',
    '悦然', '悦涵', '悦雨', '悦彤', '悦怡', '悦颖', '悦远', '悦源', '悦琪', '悦涵'
  ]

  // 随机打乱数组
  for (let i = secondNames.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [secondNames[i], secondNames[j]] = [secondNames[j], secondNames[i]]
  }

  // 确保名字不重复
  const nameIndex = (index * 2) % names.length
  const secondNameIndex = (index * 2 + 1) % secondNames.length
  const name = names[nameIndex] + secondNames[secondNameIndex]

  // 基础学习时长（3-10小时）
  const baseStudyHours = 3 + Math.random() * 7

  // 根据学习时长确定活跃度
  let activityLevel
  if (baseStudyHours >= 8) {
    activityLevel = '高'
  } else if (baseStudyHours >= 5) {
    activityLevel = '中'
  } else {
    activityLevel = '低'
  }

  // 根据学习时长计算活跃度百分比（正相关）
  const activityPercentage = Math.floor(40 + (baseStudyHours - 3) * 8)

  // 视频观看次数与学习时长正相关
  const videoWatchCount = Math.floor(baseStudyHours * 3 + Math.random() * 2)

  // 视频重播率与学习时长正相关
  const videoReplayRate = Math.floor(40 + (baseStudyHours - 3) * 7)

  // 添加详细的视频学习行为数据
  const videoLearningData = [
    {
      chapter: '电磁感应',
      watchCount: Math.floor(baseStudyHours * 4 + Math.random() * 3),
      avgDuration: Math.floor(25 + (baseStudyHours - 3) * 5),
      replayRate: Math.floor(60 + (baseStudyHours - 3) * 8),
      fastForwardCount: Math.floor(baseStudyHours * 2),
      rewindCount: Math.floor(baseStudyHours * 3)
    },
    {
      chapter: '牛顿定律',
      watchCount: Math.floor(baseStudyHours * 3 + Math.random() * 2),
      avgDuration: Math.floor(20 + (baseStudyHours - 3) * 4),
      replayRate: Math.floor(50 + (baseStudyHours - 3) * 6),
      fastForwardCount: Math.floor(baseStudyHours * 1.5),
      rewindCount: Math.floor(baseStudyHours * 2)
    },
    {
      chapter: '三角函数',
      watchCount: Math.floor(baseStudyHours * 2.5 + Math.random() * 2),
      avgDuration: Math.floor(18 + (baseStudyHours - 3) * 3),
      replayRate: Math.floor(45 + (baseStudyHours - 3) * 5),
      fastForwardCount: Math.floor(baseStudyHours * 1.2),
      rewindCount: Math.floor(baseStudyHours * 1.8)
    },
    {
      chapter: '化学反应',
      watchCount: Math.floor(baseStudyHours * 2 + Math.random() * 2),
      avgDuration: Math.floor(15 + (baseStudyHours - 3) * 3),
      replayRate: Math.floor(40 + (baseStudyHours - 3) * 4),
      fastForwardCount: Math.floor(baseStudyHours),
      rewindCount: Math.floor(baseStudyHours * 1.5)
    }
  ]

  // 平均在线时长与学习时长正相关
  const avgOnlineTime = Math.floor(60 + (baseStudyHours - 3) * 10)

  // 登录趋势与学习时长正相关
  const loginTrend = Math.floor(-5 + (baseStudyHours - 3) * 4)

  // 时间趋势与学习时长正相关
  const timeTrend = Math.floor(-8 + (baseStudyHours - 3) * 3)

  return {
    name,
    class: className,
    subject: '数学',
    dailyLogins: (baseStudyHours * 0.5 + Math.random()).toFixed(1),
    loginTrend,
    avgOnlineTime,
    timeTrend,
    activityLevel,
    activityPercentage,
    weeklyStudyHours: Math.floor(baseStudyHours * 10) / 10,
    videoWatchCount,
    videoReplayRate,
    videoLearningData,
    courseTimeData: [
      {
        course: '数学',
        time: `${Math.floor(baseStudyHours * 10) / 10}小时/周`,
        progress: activityPercentage
      },
      {
        course: '物理',
        time: `${Math.floor((baseStudyHours - 1) * 10) / 10}小时/周`,
        progress: Math.floor(activityPercentage - 5)
      },
      {
        course: '英语',
        time: `${Math.floor((baseStudyHours - 0.5) * 10) / 10}小时/周`,
        progress: Math.floor(activityPercentage - 3)
      },
      {
        course: '语文',
        time: `${Math.floor((baseStudyHours - 1.5) * 10) / 10}小时/周`,
        progress: Math.floor(activityPercentage - 7)
      }
    ]
  }
}

// 为每个班级生成45条学生数据
const classes = ['初二(1)班', '初二(2)班', '初二(3)班', '初二(4)班']
classes.forEach(className => {
  for (let i = 0; i < 45; i++) {
    learningProcessData.push(generateRandomStudent(className, i))
  }
})

// 生成电磁感应章节的统计数据
export const electromagneticStats = {
  totalStudents: learningProcessData.length,
  watchCountStats: {
    high: learningProcessData.filter(student =>
      student.videoLearningData[0].watchCount >= 15
    ).length,
    medium: learningProcessData.filter(student =>
      student.videoLearningData[0].watchCount >= 10 && student.videoLearningData[0].watchCount < 15
    ).length,
    low: learningProcessData.filter(student =>
      student.videoLearningData[0].watchCount < 10
    ).length
  },
  replayRateStats: {
    high: learningProcessData.filter(student =>
      student.videoLearningData[0].replayRate >= 70
    ).length,
    medium: learningProcessData.filter(student =>
      student.videoLearningData[0].replayRate >= 50 && student.videoLearningData[0].replayRate < 70
    ).length,
    low: learningProcessData.filter(student =>
      student.videoLearningData[0].replayRate < 50
    ).length
  },
  operationStats: {
    rewindCount: learningProcessData.reduce((sum, student) =>
      sum + student.videoLearningData[0].rewindCount, 0
    ),
    fastForwardCount: learningProcessData.reduce((sum, student) =>
      sum + student.videoLearningData[0].fastForwardCount, 0
    )
  },
  avgWatchDuration: Math.round(
    learningProcessData.reduce((sum, student) =>
      sum + student.videoLearningData[0].avgDuration, 0
    ) / learningProcessData.length
  )
}

export default learningProcessData
